home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch03 / define.h < prev    next >
C/C++ Source or Header  |  1993-05-21  |  5KB  |  187 lines

  1. /****************************************************************
  2. * FILE:    define.h
  3. * DESC:    These are the main defines for dissolve, warp, 
  4. *        morph, load and fix.
  5. * HISTORY:    Created     1/11/1993
  6. * LAST CHANGED:  5/ 6/1993
  7. *    Copyright (c) 1993 by Scott Anderson
  8. *
  9. ****************************************************************/
  10.  
  11. /* ----------------------DEFINES------------------------------ */
  12.  
  13. #define ON                1
  14. #define OFF                0
  15.  
  16. #define MAX_TWEENS        99        /* Maximum tweens (2 digits) */
  17. /* minus 2 digit tween# appended to end */
  18. #define MAX_NAME_SIZE    (8-2)    
  19.  
  20. #define HEADER_LEN        128        /* PCX header length */
  21. /* Number of colors in the palette */
  22. #define COLORS            256        
  23. /* bytes in palette (COLORS*3) */
  24. #define PALETTE_SIZE    (3*COLORS)    
  25.  
  26. /* Maximum number of morphing lines */
  27. #define MAX_LINES        32        
  28. /* max number of pixels wide we handle */
  29. #define MAX_WIDE        320        
  30. /* max number of pixels tall we handle */
  31. #define MAX_TALL        200        
  32. /* Size of screen buffer */
  33. #define    MAX_BYTES        (MAX_WIDE*(long) MAX_TALL)    
  34. /* Number of components per color (RGB) */
  35. #define COMPS            3        
  36. /* largest color component value */
  37. #define MAX_COMP        32        
  38. /* the midpoint of the colors - for gray */
  39. #define MID_COMP        (MAX_COMP/2)    
  40. /* enough to handle about 10 different palettes */
  41. #define MAX_FREQ         1023    
  42. #define MAX_FILES        10
  43. /* length of a file name including directory */
  44. #define MAX_PATHLEN     80      
  45.  
  46. #define ENTER            13        /* Keyboard values */
  47. #define    ESC                27
  48.  
  49. #define HTAB            18        /* Position for text messages */
  50. #define VTAB            8
  51.  
  52. /* The mouse button & keyboard constants */
  53. #define NO_BUTTON        0        
  54. #define LEFT_BUTTON        1
  55. #define RIGHT_BUTTON    2
  56. #define KEYPRESS        4
  57.  
  58. /* the square of min dist for grabbing pt */
  59. #define GRAB_DISTANCE    25        
  60.  
  61. /* Some of the graphics colors */
  62. #define    BLACK            0        
  63. #define WHITE            255
  64.  
  65. #define EXT_PCX         ".PCX"    /* pcx file extension */
  66. /* primary line file holder extension */
  67. #define EXT_LINE1        ".LN1"    
  68. #define EXT_LINE2        ".LN2"    /* aux file for warp lines */
  69.  
  70. #define ERROR             -1        /* General-purpose error code */
  71.  
  72. typedef enum {
  73.     NO_ERROR,            /* first entry means everything is ok */
  74.     MEMORY_ERR,            /* Not enough memory */
  75.     READ_OPEN_ERR,         /* Couldn't open file for reading */
  76.     READ_ERR,              /* Trouble reading the file */
  77.     WRITE_OPEN_ERR,        /* Couldn't open the file for writing */
  78.     WRITE_ERR,              /* Couldn't write the file */
  79.     MOUSE_ERR,              /* No mouse driver found */
  80.     WRONG_PCX_FILE,        /* PCX file format not supported yet */
  81.     READ_CONTENTS_ERR   /* error in .LN file */
  82. }
  83. ERR;
  84.  
  85. /* -----------------------MACROS------------------------------ */
  86.  
  87. #define MIN(a,b)        (((a)<(b)) ? (a) : (b))
  88. #define PIXEL(p,x,y)    (p->pixmap[y * (long) p->wide + x])
  89. #define SQUARE(x)         (((long) x)*(x))
  90.  
  91. /* ----------------------TYPEDEFS----------------------------- */
  92.  
  93. typedef struct {
  94.     int x,y;               /* the screen coordinates of the point */
  95. }
  96. POINT;
  97.  
  98. typedef struct {
  99.     POINT p[2];
  100. }
  101. LINE_SEGMENT;
  102.  
  103. typedef struct {
  104.     int number;        /* number of segments to follow */
  105.     LINE_SEGMENT line[MAX_LINES];
  106.     char *filename;    /* name of file holding the line list */
  107. }
  108. LINE_LIST;
  109.  
  110.  
  111. typedef struct {
  112.     POINT p[2];                /* the endpoints */
  113.     int delta_x, delta_y;    /* x & y displacement */
  114.     float length;        /* the precalculated length of the line */
  115.     long length_square;        /* the length squared */
  116. }
  117. LINE;
  118.  
  119. typedef struct {
  120.     /* red, green, and blue color components */
  121.     unsigned char r, g, b;    
  122. }
  123. COLOR;
  124.  
  125. typedef struct {
  126.     COLOR c[COLORS];        /* a 256 entry palette */
  127. }
  128. PALETTE;
  129.  
  130. typedef struct {
  131.     int xmin, ymin;            /* the upper left corner */
  132.     int xmax, ymax;            /* the lower right corner */
  133.     int wide, tall;            /* the width and height */
  134.     int pal_id;                /* an ID number for each palette */
  135.     PALETTE pal;            /* the actual palette is here */
  136.     unsigned char far *pixmap;    /* a pointer to the pixel map */
  137. }
  138. PICTURE;
  139.  
  140. typedef struct linko {
  141.     struct linko *next;
  142.     char        *str;
  143. }
  144. LINKED_LIST;
  145.  
  146. /* ----------------------PROTOTYPES--------------------------- */
  147.  
  148. /**** file handling routines ****/
  149. extern PICTURE    *loadPicture(char *filename);
  150. extern int        loadPalette(FILE *fp, PALETTE *palette);
  151. extern int        getBlock (unsigned char *byte, int *count, 
  152.                                                     FILE *fp);
  153. extern int        mustRead(FILE *fp, char *buf, int n);
  154. extern int        saveScreen(PALETTE *pal);
  155. extern int        putBlock(unsigned char num, unsigned char color, 
  156.                                                     FILE *fp);
  157. extern int        writeByte(unsigned char *byte, FILE *fp);
  158.  
  159. /**** screen and color routines ****/
  160. extern int        defaultPalette(PALETTE *palette);
  161. extern int        setPalette(PALETTE *palette);
  162. extern int        displayPicture(PICTURE *picture);
  163. extern int        displayNoPal(PICTURE *picture);
  164. extern int        freePicture(PICTURE *pic);
  165.  
  166. /**** mouse routines ****/
  167. extern int        initMouse();
  168. extern int        hideMouse();
  169. extern int        showMouse();
  170. extern int        mousePos(int *x, int *y);
  171.  
  172. /**** general purpose routines ****/
  173. extern int        clip(int num, int min, int max);
  174. extern int        quitCheck();
  175. extern void        quit(int err, char *name);
  176. extern int        wait(int count);
  177. extern int        waitForKey();
  178. extern char        lineAsk(char *name);
  179.  
  180. /* ----------------------GLOBAL DATA-------------------------- */
  181.  
  182. extern int        TargFlag;
  183. extern int        Key;
  184.  
  185.